Skip to content

hash: max and min in parentheses in every header, so a bare <windows.h> before them compiles - #20

Merged
pinhopro merged 2 commits into
mainfrom
hash/windows-h-macros
Dec 4, 2026
Merged

pinhopro merged 2 commits into
mainfrom
hash/windows-h-macros

Conversation

@pinhopro

@pinhopro pinhopro commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

A bare <windows.h> (no NOMINMAX) defines the macros min and max for the whole program. detail/limits.hpp wrote std::numeric_limits<std::size_t>::max(), so any program that includes webcpp::hash's KDF headers after <windows.h> stops on MSVC with C2589. crypto's HPKE (webcpporg/crypto, branch crypto/hpke) includes hash/hkdf.hpp, and crypto's windows_h_before test hit this on MSVC 14.3 and 14.5 (it is the only test that puts <windows.h> first).

  • Every header in include/ now uses (std::min)(a, b), and SIZE_MAX, UINT64_MAX and ULLONG_MAX in place of std::numeric_limits<T>::max(). No macro expands any of these, and clang-tidy's readability-redundant-parentheses accepts them, which it does not for (std::numeric_limits<T>::max)(). 10 headers changed, no behaviour change.
  • New test windows_h: a bare <windows.h>, then every public header with OpenSSL, BearSSL and libsodium linked, then HKDF over spans and over pieces. It runs natively; off Windows it only compiles and calls.

The changelog is unchanged: the code is unreleased, and the unreleased section is already at ten lines.

Verified locally:

  • MSVC 14.3 x64 debug: hash's windows_h passes, and so do crypto's windows_h_before and HPKE's tests built against it. Before the fix, crypto's windows_h_before failed with C2589 at detail/limits.hpp(45) and (63).
  • clang (macOS): windows_h passes.
  • clang-format: clean.

This merges before crypto's HPKE. The superproject's gitlink of hash moves with the HPKE test vectors (webcpporg/webcpp branch third_party/hpke-vectors).

🤖 Generated with Claude Code

…dows.h> before them compiles

A bare <windows.h> defines the macros min and max for the whole program.
detail/limits.hpp's std::numeric_limits<std::size_t>::max() then stopped MSVC
with C2589 in any program that included webcpp::hash's KDF headers after it:
crypto's HPKE, which calls hkdf over pieces, met it in crypto's
windows_h_before test on MSVC 14.3. Every header now writes
(std::numeric_limits<T>::max)() and (std::min)(a, b), as crypto's do, and
the test windows_h includes every public header after a bare <windows.h>,
with every backend linked, and calls HKDF over spans and over pieces.
clang-tidy's readability-redundant-parentheses reports
(std::numeric_limits<T>::max)(), the form the previous commit used against
<windows.h>'s max macro. The <cstdint> and <climits> constants name the same
values, and no macro expands them.
@pinhopro
pinhopro merged commit d7ea49c into main Dec 4, 2026
11 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant